package main;

public class SolveEquation {
	private Double a,b,c;
	private boolean tooMuch;
	private Pair<MyDouble> sol;

	public SolveEquation(double x, double y, double z) {
		double d = y*y - 4*x*z;
		tooMuch = (x==0.0 && y==0.0 && z==0.0);
		sol = new Pair<MyDouble>(
			new MyDouble((-y-Math.sqrt(d))/2/x), 
			new MyDouble((-y+Math.sqrt(d))/2/x));
		a = x; b = y; c = z;
	}

	private boolean badOne() {
		return Double.isNaN(sol.getE1().doubleValue());
	}

	public int getNbSolutions() throws ArithmeticException {
		if (tooMuch)
			throw new ArithmeticException("inf");
		else if (badOne())
			return 0;
		else
			return (sol.isIdenticalPair() ? 1 : 2);
	}

	public Pair<MyDouble> getSolutions() throws ArithmeticException {
		if (badOne())
			throw new ArithmeticException("no");
		else
			return sol;
	}
}
